package com.SNQ.project.English_speaking_learning_system.mapper;

import com.SNQ.project.English_speaking_learning_system.aspect.AutoFill;
import com.SNQ.project.English_speaking_learning_system.common.enumeration.OperationType;
import com.SNQ.project.English_speaking_learning_system.pojo.dto.ArticlePageQueryDTO;
import com.SNQ.project.English_speaking_learning_system.pojo.entity.Article;
import com.SNQ.project.English_speaking_learning_system.pojo.vo.ArticleVO;
import com.github.pagehelper.Page;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface ArticleMapper {

    /**
     * 根据分类id查询文章
     * @param categoryId
     * @return
     */
    @Select("select count(id) from article where category_id = #{categoryId}")
    Integer countByCategoryId(Long categoryId);

    /**
     * 插入文章信息
     * @param article
     */
    @AutoFill(value = OperationType.INSERT)
    void insert(Article article);

    /**
     * 文章分页查询
     * @param articlePageQueryDTO
     * @return
     */
    Page<ArticleVO> pageQuery(ArticlePageQueryDTO articlePageQueryDTO);

    /**
     * 根据主键查询文章
     * @param id
     * @return
     */
    @Select("select * from article where id = #{id}")
    Article getById(Long id);

    /**
     * 根据主键删除文章信息
     * @param id
     */
    @Delete("delete from article where id = #{id}")
    void deleteById(Long id);

    /**
     * 根据id动态修改文章信息
     * @param article
     */
    @AutoFill(value = OperationType.UPDATE)
    void update(Article article);

    /**
     * 动态查询文章
     * @param article
     * @return
     */
    List<Article> list(Article article);

    @Select("select content from article where id = #{id}")
    String getArticleContentById(Long id);
}
